//
//  AuthenticationVC.m
//  ZZLC
//
//  Created by 杨春至 on 2017/12/15.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "AuthenticationVC.h"
#import "HasAuthenVC.h"
#import "InvestTableViewCell.h"
#import "BankListVC.h"



@interface AuthenticationVC ()<UITableViewDelegate,UITableViewDataSource,TTTAttributedLabelDelegate>
{
    NSArray *_titleArray;
    NSArray *_canEditArray;
    NSArray *_placeHodlerArray;
    NSMutableArray *_dataArrary;
}
@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSMutableArray *dataSource;

@property (nonatomic,strong) UIButton *investBtn;

@property (nonatomic,strong) TTTAttributedLabel *infoLb;

@end

@implementation AuthenticationVC
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"实名认证";
//    _hasAuthent = NO;
    if (!_hasAuthent) {
        [self loadData];
        [self configUI];
    }else{
        HasAuthenVC *hasVC = [[HasAuthenVC alloc]init];
        [self addChildViewController:hasVC];
        [self.view addSubview:hasVC.view];
    }

}
- (void)loadData{
    _titleArray = @[@[@"充值金额"],@[@"姓名",@"身份证号",@"银行",@"银行卡号"]];
    _canEditArray = @[@[@1],@[@1,@1,@0,@1]];
    _dataArrary = @[@[@""],@[@"",@"",@"",@""]].mutableCopy;
    _placeHodlerArray = @[@[@"请输入大于等于100元的金额"],@[@"请输入您的真实姓名",@"请输入身份证号",@"请选择银行",@"请输入银行卡号"]];
}
- (void)configUI{
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.investBtn];
}
- (void)viewDidLayoutSubviews{
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 44, 0));
    }];
    [_investBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(_tableView.mas_bottom);
        make.bottom.equalTo(self.view);
    }];
    
}
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url{
    [self jumpToH5VCByURL:[NSString stringWithFormat:@"%@%@",HOSTURL_FOR_REPORT,@"assetzz/mobileH5/prompt.jsp"]];
}
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithPhoneNumber:(NSString *)phoneNumber{
    [self setupPhone:phoneNumber];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1 &&indexPath.row == 2) {
        BankListVC *bankVC = [[BankListVC alloc]init];
        [self.navigationController pushViewController:bankVC animated:YES];
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
        return self.infoLb;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [UIView new];
    if (section == 1) {
        TTTAttributedLabel *lb = [TTTAttributedLabel new];
        lb.numberOfLines = 0;
        lb.text = @"温馨提示 :\n1、充值、提现零手续费;\n2、充值金额即时到账(如遇网络繁忙,节假日等会有段时间延迟);\n3、如遇充值问题,请联系客服0571-86076015;\n4、充值错误代码;";
        lb.frame = CGRectMake(15, 0, KWidth - 2*15, 160);
        lb.font = [UIFont systemFontOfSize:6];
        lb.textColor = RGBCOLOR(161, 161, 161);
        [footerView addSubview:lb];
        lb.font = [UIFont systemFontOfSize:12];
        NSRange phoneRange = [lb.text rangeOfString:@"0571-86076015" options:NSCaseInsensitiveSearch];
        NSRange coedRange = [lb.text rangeOfString:@"充值错误代码" options:NSCaseInsensitiveSearch];
        [lb addLinkToURL:[NSURL URLWithString:@"充值错误代码"] withRange:coedRange];
        [lb addLinkToPhoneNumber:@"0571-86076015" withRange:phoneRange];
        NSMutableAttributedString *mstr = [[NSMutableAttributedString alloc]initWithString:lb.text attributes:@{NSForegroundColorAttributeName:RGBCOLOR(171, 171, 171)}];
        [mstr addAttribute:NSForegroundColorAttributeName value:ZZGoldColor range:phoneRange];
        [mstr addAttribute:NSForegroundColorAttributeName value:ZZGoldColor range:coedRange];
        lb.attributedText = mstr;
        lb.delegate = self;
        return footerView;
    }else{
        return nil;
        
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0.001f;
    }else if (section == 1) {
        return 35.0f;
    }else{
        return 40;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 1) {
        return 130;
    }else {
        return 0.001f;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    InvestTableViewCell *cell = [[[NSBundle mainBundle]loadNibNamed:@"InvestTableViewCell" owner:nil options:NULL]firstObject];
    [cell setTitleStr:_titleArray[indexPath.section][indexPath.row] canEditStr:[_canEditArray[indexPath.section][indexPath.row] boolValue] editText:_dataArrary[indexPath.section][indexPath.row] placeHodel:_placeHodlerArray[indexPath.section][indexPath.row]];
    if (indexPath.section!=0) {
        [cell hideRightUnitLb];
    }
    if (indexPath.section == 1&&indexPath.row == 2) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50.0f;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _titleArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *array = _titleArray[section];
    return array.count;
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (TTTAttributedLabel *)infoLb{
    if (!_infoLb) {
        _infoLb = [TTTAttributedLabel new];
        _infoLb.frame = CGRectMake(0, 0, KWidth, 35);
        [_infoLb setStlyeByText:@"       请输入您本人的身份信息" andLinkText:@""];
        _infoLb.delegate = self;
    }
    return _infoLb;
}


- (UIButton *)investBtn{
    if (!_investBtn) {
        _investBtn = [[UIButton alloc]init];
        [_investBtn setBackgroundImage:UIImageMake(@"bottombtnbgcolor") forState:UIControlStateNormal];
        [_investBtn setTitle:@"立 即 充 值" forState:UIControlStateNormal];
        [_investBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _investBtn.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        [_investBtn bk_addEventHandler:^(id sender) {
            //       支付
        } forControlEvents:UIControlEventTouchUpInside];
    }
    return _investBtn;
}

@end
